// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        richTxt: cc.RichText,
        btnOk: cc.Button,
        btnCancal: cc.Button,
        title: cc.Sprite,
        pointArr: {
            default: [],
            type: [cc.Vec2]
        },
        _itemNode: null,
        _build: null,
    },

    setUINode(node) {
        this._itemNode = node;
        this.setBuild(node.getComponent('WindowBuild'));
    },

    setBuild(build) {
        this._build = build;
    },

    getBuild() {
        return this._build;
    },

    onLoad() {},


    showWithCancelMsg(str, funOk) {
        this._okFunCallBack = null;
        this._cancelFunCallBack = null;
        if (typeof (funOk) != "undefined") {
            this._okFunCallBack = funOk;
        }
        this.btnOk.node.setPosition(this.pointArr[0]);
        this.btnOk.node.active = true;
        this.btnCancal.node.setPosition(this.pointArr[1]);
        this.btnCancal.node.active = true;
        this.richTxt.string = str;
        cc.windowManager.showWindow(this);
    },

    showMsg(str, funOk, funCancel) {
        this._okFunCallBack = null;
        this._cancelFunCallBack = null;
        this.btnCancal.node.active = false;
        this.btnOk.node.active = true;
        this.btnOk.node.setPosition(this.pointArr[2]);
        if (typeof (funOk) != "undefined") {
            this._okFunCallBack = funOk;

        }

        if (typeof (funCancel) != "undefined") {
            this._cancelFunCallBack = funCancel;
            this.btnOk.x = this.pointArr[0].x;
            this.btnCancal.x = this.pointArr[1].x;

            // this.btnOk.setPosition(this.pointArr[0]);
            // this.btnCancal.setPosition(this.pointArr[1]);
            this.btnCancal.active = true;
            // this.btnCancal.setVisible(true);
        }
        this.richTxt.string = str;
        cc.windowManager.showWindow(this);
    },

    dismiss() {
        cc.windowManager.dismissWindow(this);
    },

    onViewClickListener(sender, data) {
        if (data == 'ok') {
            if (this._okFunCallBack) {
                this._okFunCallBack();
            }
            this.dismiss();
        } else if (data == 'cancel') {
            if (this._cancelFunCallBack) {
                this._cancelFunCallBack();
            }
            this.dismiss();
        }
        // var view = sender.currentTarget.getComponent(cc.Button);
        // if (view == this.btnOk) {
        // if (this._okFunCallBack) {
        //     this._okFunCallBack();
        // }
        // this.dismiss();
        // } else if (view == this.btnCancal) {
        // if (this._cancelFunCallBack) {
        //     this._cancelFunCallBack();
        // }
        // this.dismiss();
        // } else if (view == this._btnClose) {
        //     if (this._cancelFunCallBack) {
        //         this._cancelFunCallBack();
        //     }
        //     this.dismiss();
        // }
    }

    // start () {

    // },

    // update (dt) {},
});